|
|
 |
|
|
|
|
' Create the new grid object. Set TheGrid = New Grid3d
TheGrid.SetBounds Xmin, Dx, NumX, Zmin, Dz, NumZ
' Fill in data values. X = Xmin
For i = 1 To NumX
Z = Zmin
For j = 1 To NumZ ' Find the closest data value. best_i = NearestPoint(X, Z)
' Add the value to the grid. TheGrid.SetValue X, Data(best_i).coord(2), Z
Z = Z + Dz
Next j
X = X + Dx
Next i
End Sub |
|
|
|
|
|
|
|
|
Example program Surface3 uses the SparseGrid3d class to display a surface that approximates incomplete data. Use the option buttons to select a surface type. The program randomly picks several hundred X and Z values on the surface within the region 5 <= X <= 5, 5 <= Z <= 5. It stores those data values in a SparseGrid3d object. |
|
|
|
|
|
|
|
|
Next, the program invokes the object's InitializeGrid routine to create and initialize the display grid. The program then uses the object's Draw method to make the SparseGrid3d display the data. |
|
|
|
|
|
|
|
|
Figure 14.7 shows a grid approximating a set of data randomly chosen from the values displayed in Figure 14.2. The surface shown in Figure 14.7 follows the general shape of the data, but it is quite blocky. As you move through the display grid's X and Z coordinates, the nearest data value suddenly jumps from one value to another. Because you use only the nearest data value to set the grid values, the grid values also jump suddenly, creating steep slopes and artificial flat surfaces that are probably not part of the true data. You can reduce the effects of these sudden jumps by initializing the grid data in a different way. |
|
|
|
|
|
|
|
|
Instead of considering only the data value nearest to each grid position, consider several values and take a weighted average. The version of the subroutine InitializeGrid that follows begins as before, finding bounds for the data, creating the display grid object, and setting its data bounds. |
|
|
|
|
|
|
|
|
Then, for each grid location, the routine locates the four closest data points to the upper left, upper right, lower left, and lower right of the grid location. This gives the routine data values that surround the grid location's value. |
|
|
|
|
|
|
|
|
Sometimes one or two of these surrounding values will be missing. If the grid location is at the left edge of the data, there will be no data values to the upper left or lower left of the grid location. Still, for most grid locations, this method gives several points surrounding the target location. |
|
|
|
|
|